package com.example.base;


import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @Title: TestList
 * @Description: TODO
 * @Date 2020/6/24 11:26
 */
public class TestList {

    public static void main(String[] args) {
        List<String> platformList = new ArrayList<>();
        platformList.add("博客园");
        platformList.add("CSDN");
        platformList.add("掘金");
        Iterator<String> iterator = platformList.iterator();
        while (iterator.hasNext()) {
            String platform = iterator.next();
            if (platform.equals("博客园")) {
                iterator.remove();
            }
        }
        System.out.println(platformList);


        platformList = new ArrayList<>();
        platformList.add("博客园");
        platformList.add("博客园");
        platformList.add("CSDN");
        platformList.add("掘金");
        for (int i = 0; i < platformList.size(); i++) {
            String item = platformList.get(i);
            if ("博客园".equals(item)) {
                platformList.remove(i);
                i = i - 1;
            }
        }
        System.out.println(platformList);

        platformList = new ArrayList<>();
        platformList.add("博客园");
        platformList.add("CSDN");
        platformList.add("掘金");
        for (String platform : platformList) {
            if (platform.equals("博客园")) {
                platformList.remove(platform);
            }
        }
        System.out.println(platformList);
    }
}
